package com.dcivision.workflow.applet;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.ObjectInputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import javax.swing.ButtonGroup;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.TitledBorder;

import com.dcivision.dms.client.HtmlFormText;
import com.dcivision.framework.Utility;
import com.dcivision.setup.bean.SetupOptionWorkflowCategory;
import com.dcivision.workflow.applet.editor.CalendarControl;
import com.dcivision.workflow.applet.net.HttpOperation;
import com.dcivision.workflow.bean.MtmWorkflowRecordObjectLink;
import com.dcivision.workflow.bean.WorkflowGroup;
import com.dcivision.workflow.bean.WorkflowRecord;
import com.dcivision.workflow.core.SystemWorkflowConstant;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class WorkflowRecordInfoWindow extends JDialog {

  public static final String REVISION = "$Revision: 1.10 $";


  //Define Control
  JPanel panel1 = new JPanel();
  JLabel jLabel1 = new JLabel();
  JTextField jTFWorkflowCode = new JTextField();
  JLabel jLabel2 = new JLabel();
  JTextField jTFWorkflowVer = new JTextField();
  JLabel jLabel3 = new JLabel();
  JComboBox jCBWorkflowCategory = new JComboBox();
  JLabel jLabel4 = new JLabel();
  JComboBox jCBWorkflowGroup = new JComboBox();
  JLabel jLabel5 = new JLabel();
  JLabel jLabel6 = new JLabel();
  JTextArea jTADescription = new JTextArea();
  JTextField jTFStartDate = new JTextField();
  JTextField jTFEndDate = new JTextField();
  TitledBorder titledBorder1;
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  JLabel jLabel7 = new JLabel();
  JTextField jTFCategoryObject = new JTextField();
  JButton jButton3 = new JButton();
  JButton jButton4 = new JButton();
  JLabel jLabel8 = new JLabel();
  JLabel jLabel9 = new JLabel();
  JComboBox jCBStatus = new JComboBox();

  //String [] boundList = {"item [1]","item [2]","item [2]","item [2]","item [2]"};
  JList jList = new JList();
  JScrollPane jBoundList = new JScrollPane(jList);

  //Define URL
  String hostURL = "";
  String getDataURL = "/workflow/appletMiddleware?dataType=GET_CATEGORYGROUP";

  String maintWorkflowRecordURL = "/workflow/MaintWorkflowRecord.do?fromType=A";
  //
  HttpOperation httpOperation = null;

  TreeUseWorkflowRecord treeUseWorkflowRecord ;
  WorkflowRecord workflowRecord;
  String interruptSubmitter="";

  //
  String navMode        = "N";
  String opMode         = "INS";
  String ID             = "";
  String recordStatus   = "";
  String updateCount    = "";
  String creatorID      = "";
  String createDate     = "";
  String updaterID      = "";
  String updateDate     = "";

  Integer groupID ;

  WorkflowEditor workflowEditor;
  JLabel jLabel10 = new JLabel();
  ButtonGroup buttonGroup1 = new ButtonGroup();
  JRadioButton jRBno = new JRadioButton();
  JRadioButton jRByes = new JRadioButton();
  JLabel jLabel11 = new JLabel();
  JComboBox jCBInterruptWorkflowRecordID = new JComboBox();
  JTextField jTFlocationPath = new JTextField();
  JButton jButton5 = new JButton();
  JLabel jLabel12 = new JLabel();
  JButton jBPermission = new JButton();

  public void setParentWindow(WorkflowEditor workflowEditor){
    this.workflowEditor = workflowEditor;
  }

  public void setNavMode(String navMode){
    this.navMode = navMode;
  }

  public void setOpMode(String opMode){
    this.opMode = opMode;
  }

  public void setTreeUseWorkflowRecord(TreeUseWorkflowRecord treeUseWorkflowRecord ){
    this.treeUseWorkflowRecord =  treeUseWorkflowRecord;
  }

  public void setGroupID (Integer groupID){
    this.groupID = groupID;
  }

  public WorkflowRecordInfoWindow(Frame frame, String title, boolean modal) {
    super(frame, title, modal);
    try {
      jbInit();
      pack();
    }
    catch(Exception ex) {
      ex.printStackTrace();
    }
  }

  public WorkflowRecordInfoWindow(HttpOperation httpOperation,String hostURL,Integer groupID) {
    super();
    this.httpOperation = httpOperation;
    this.hostURL = hostURL;
    this.groupID = groupID;
    try {
      jbInit();
      pack();
    }
    catch(Exception ex) {
      ex.printStackTrace();
    }
  }

  public WorkflowRecordInfoWindow() {
    this(null, "", false);
  }

  private void jbInit() throws Exception {
    int top = 20;
    int space = 30;
    int curTop = top;
    titledBorder1 = new TitledBorder("");
    panel1.setLayout(null);
    jLabel1.setBackground(Color.lightGray);
    jLabel1.setForeground(Color.red);
    jLabel1.setHorizontalTextPosition(SwingConstants.RIGHT);
    jLabel1.setText(AppletResource.lableArr[11]+":");
    jLabel1.setVerticalAlignment(SwingConstants.CENTER);
    jLabel1.setVerticalTextPosition(SwingConstants.CENTER);
    jLabel1.setBounds(new Rectangle(11, 25, 100, 16));
    jTFWorkflowCode.setText("");
    jTFWorkflowCode.setBounds(new Rectangle(119, 20, 99, 22));
    jLabel2.setForeground(Color.red);
    jLabel2.setText(AppletResource.lableArr[12]+":");
    jLabel2.setBounds(new Rectangle(219, 23, 59, 16));
    jTFWorkflowVer.setText("");
    jTFWorkflowVer.setBounds(new Rectangle(280, 20, 104, 22));
    curTop += 30;
    jLabel3.setForeground(Color.red);
    jLabel3.setHorizontalTextPosition(SwingConstants.RIGHT);
    jLabel3.setText(AppletResource.lableArr[13]+":");
    jLabel3.setVerticalAlignment(SwingConstants.CENTER);
    jLabel3.setVerticalTextPosition(SwingConstants.CENTER);
    jLabel3.setBounds(new Rectangle(42, 76, 69, 16));
    jCBWorkflowCategory.setBounds(new Rectangle(117, 77, 269, 20));
    jCBWorkflowCategory.addItemListener(new ItemListener(){
      public void itemStateChanged(ItemEvent event){
        int state = event.getStateChange();
        ListObject workflowCategoryRecord = (ListObject)event.getItem();
        Integer cotegoryID = new Integer(workflowCategoryRecord.getID());
        initBindList(cotegoryID);

      }
    });


    curTop += 30;
    jLabel4.setForeground(Color.red);
    jLabel4.setHorizontalTextPosition(SwingConstants.RIGHT);
    jLabel4.setText(AppletResource.lableArr[15]+":");
    jLabel4.setVerticalAlignment(SwingConstants.CENTER);
    jLabel4.setVerticalTextPosition(SwingConstants.CENTER);
    jLabel4.setBounds(new Rectangle(8, 51, 103, 16));
    jCBWorkflowGroup.setBounds(new Rectangle(118, 49, 266, 20));
    curTop += 30;
    jLabel7.setBounds(new Rectangle(34, 110, 77, 16));
    jLabel7.setText(AppletResource.lableArr[14]+":");
    jLabel7.setVerticalAlignment(SwingConstants.CENTER);
    jLabel7.setVerticalTextPosition(SwingConstants.CENTER);
    jLabel7.setForeground(Color.red);
    jLabel7.setToolTipText("");
    jLabel7.setHorizontalTextPosition(SwingConstants.RIGHT);
    jBoundList.setBounds(new Rectangle(119, 110, 263, 60));
    curTop += 70;
    jLabel5.setForeground(Color.red);
    jLabel5.setHorizontalAlignment(SwingConstants.RIGHT);
    jLabel5.setHorizontalTextPosition(SwingConstants.RIGHT);
    jLabel5.setText(AppletResource.lableArr[16]+":");
    jLabel5.setVerticalAlignment(SwingConstants.CENTER);
    jLabel5.setVerticalTextPosition(SwingConstants.CENTER);
    jLabel5.setBounds(new Rectangle(2, 173, 109, 20));
    jTFStartDate.setText(WindowUtilities.getCurrentDateStr());
    jTFStartDate.setBounds(new Rectangle(119, 173, 80, 21));

    jButton3.setBounds(new Rectangle(205, 174, 23, 20));
    jButton3.setText("...");
    jButton3.addActionListener(new WorkflowRecordInfoWindow_jButton_actionAdapter(jTFStartDate));
    jLabel9.setText(AppletResource.lableArr[17]+":");
    jLabel9.setBounds(new Rectangle(240, 175, 30, 19));
    jTFEndDate.setText("");
    jTFEndDate.setBounds(new Rectangle(273, 174, 80, 20));
    jButton4.setBounds(new Rectangle(358, 175, 23, 20));
    jButton4.setText("...");
    jButton4.addActionListener(new WorkflowRecordInfoWindow_jButton_actionAdapter(jTFEndDate));



    curTop += 30;
    jLabel6.setHorizontalTextPosition(SwingConstants.RIGHT);
    jLabel6.setText(AppletResource.lableArr[20]+":");
    jLabel6.setVerticalAlignment(SwingConstants.CENTER);
    jLabel6.setVerticalTextPosition(SwingConstants.CENTER);
    jLabel6.setBounds(new Rectangle(20, 278, 91, 17));
    jTADescription.setText("");
    jTADescription.setBounds(new Rectangle(118, 277, 263, 45));

    curTop += 70;
    jLabel8.setHorizontalAlignment(SwingConstants.RIGHT);
    jLabel8.setHorizontalTextPosition(SwingConstants.RIGHT);
    jLabel8.setText(AppletResource.lableArr[21]+":");
    jLabel8.setVerticalAlignment(SwingConstants.CENTER);
    jLabel8.setVerticalTextPosition(SwingConstants.CENTER);
    jLabel8.setBounds(new Rectangle(31, 329, 80, 18));
    jCBStatus.setEnabled(true);
    jCBStatus.setDebugGraphicsOptions(0);
    jCBStatus.setToolTipText("");
    jCBStatus.setBounds(new Rectangle(117, 328, 86, 21));


    this.setTitle(AppletResource.lableArr[10]);
    panel1.setBorder(null);
    panel1.setDebugGraphicsOptions(0);
    panel1.setMaximumSize(new Dimension(32767, 32767));
    panel1.setToolTipText("");
    curTop += 30;
    jButton1.setBounds(new Rectangle(134, 355, 66, 27));
    jButton1.setText(AppletResource.lableArr[24]);
    jButton1.addActionListener(new WorkflowRecordInfoWindow_jButton1_actionAdapter(this));
    jButton2.setBounds(new Rectangle(235, 355, 68, 27));
    jButton2.setText(AppletResource.lableArr[25]);
    jButton2.addActionListener(new WorkflowRecordInfoWindow_jButton2_actionAdapter(this));
    //jCBWorkflowCategory.setSelectedItem("ParaDOC Paper Document");

    //jTFCategoryObject.setText("");
    //jTFCategoryObject.setBounds(new Rectangle(119, 95, 237, 24));






    jLabel10.setHorizontalAlignment(SwingConstants.RIGHT);
    jLabel10.setHorizontalTextPosition(SwingConstants.RIGHT);
    jLabel10.setText(AppletResource.lableArr[26]);
    jLabel10.setBounds(new Rectangle(6, 202, 105, 18));
    jRBno.setSelected(true);
    jRBno.setText("no");
    jRBno.setBounds(new Rectangle(120, 199, 56, 24));
    jRByes.setText("yes");
    jRByes.setBounds(new Rectangle(182, 201, 65, 21));
    jRByes.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jRByes_actionPerformed(e);
      }
    });
    jLabel11.setText(AppletResource.lableArr[27]);
    jLabel11.setBounds(new Rectangle(67, 225, 175, 19));
    jCBInterruptWorkflowRecordID.setBounds(new Rectangle(247, 222, 135, 22));
    jTFlocationPath.setBounds(new Rectangle(119, 248, 233, 24));
    jButton5.setBounds(new Rectangle(355, 250, 29, 19));
    jButton5.setVerifyInputWhenFocusTarget(true);
    jButton5.setText("...");
    jLabel12.setHorizontalAlignment(SwingConstants.RIGHT);
    jLabel12.setHorizontalTextPosition(SwingConstants.RIGHT);
    jLabel12.setText(AppletResource.lableArr[29]);
    jLabel12.setBounds(new Rectangle(13, 247, 98, 21));
    jBPermission.setBounds(new Rectangle(273, 198, 107, 22));
    jBPermission.setText(AppletResource.lableArr[28]);
    jBPermission.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jBPermission_actionPerformed(e);
      }
    });
    getContentPane().add(panel1);
    panel1.add(jTFWorkflowCode, null);
    panel1.add(jTFWorkflowVer, null);
    //panel1.add(jTFCategoryObject, null);
    panel1.add(jBoundList,null);
    //panel1.add(jButton3, null);
    panel1.add(jLabel9, null);
    panel1.add(jLabel7, null);
    panel1.add(jCBWorkflowGroup, null);
    panel1.add(jCBWorkflowCategory, null);
    panel1.add(jLabel3, null);
    panel1.add(jLabel4, null);
    panel1.add(jTFStartDate, null);
    panel1.add(jLabel5, null);
    panel1.add(jRBno, null);
    panel1.add(jRByes, null);
    panel1.add(jLabel10, null);
    panel1.add(jButton3, null);
    panel1.add(jLabel1, null);
    panel1.add(jLabel2, null);
    panel1.add(jButton1, null);
    panel1.add(jButton2, null);
    panel1.add(jTADescription, null);
    panel1.add(jCBStatus, null);
    panel1.add(jLabel8, null);
    panel1.add(jLabel6, null);
    panel1.add(jCBInterruptWorkflowRecordID, null);
    panel1.add(jLabel11, null);
    panel1.add(jTFlocationPath, null);
    panel1.add(jButton5, null);
    panel1.add(jLabel12, null);
    panel1.add(jTFEndDate, null);
    panel1.add(jButton4, null);
    panel1.add(jBPermission, null);
    initComboBox();
    //initRecordInfo();
    buttonGroup1.add(jRBno);
    buttonGroup1.add(jRByes);
  }


  void jButton1_actionPerformed(ActionEvent e) {
    if(postDataToAction()){
      workflowEditor.reloadTree();
      this.dispose() ;
    }
  }

  void jButton2_actionPerformed(ActionEvent e) {
    this.dispose() ;
  }

  private void initComboBox(){
    ObjectInputStream inputFromServlet = null;
    List workflowGroupList = new ArrayList();
    List workflowCategoryList = new ArrayList();
    List interruptList = new ArrayList();


    // init status
    jCBStatus.addItem(AppletResource.lableArr[22]);
    jCBStatus.addItem(AppletResource.lableArr[23]);

    try{
      getDataURL = "/workflow/appletMiddleware?dataType=GET_CATEGORYGROUP";
      inputFromServlet = httpOperation.getObjectInputStreamFromServlet(getDataURL);

      if(inputFromServlet == null){
        return;
      }

      Object obj = null;
      obj = inputFromServlet.readObject();
      //get workflow group
      if (obj instanceof List) {
          workflowGroupList = (List) obj;
      } else if (obj instanceof Exception) {
          //otherwise type cast it to Exception and throw that exception.
          throw (Exception) obj;
      }
      //get workflow category
      obj = inputFromServlet.readObject();
      if (obj instanceof List) {
        workflowCategoryList = (List) obj;
      } else if (obj instanceof Exception) {
        //otherwise type cast it to Exception and throw that exception.
        throw (Exception) obj;
      }
      //get interrupt List
      obj = inputFromServlet.readObject();
      if (obj instanceof List) {
        interruptList = (List) obj;
      } else if (obj instanceof Exception) {
        //otherwise type cast it to Exception and throw that exception.
        throw (Exception) obj;
      }

    }catch (Exception e){
        e.printStackTrace();

    }


    for(int i=0; i<workflowGroupList.size() ; i++) {
      WorkflowGroup workflowGroup = (WorkflowGroup)workflowGroupList.get(i);
      TreeUseWorkflowGroup treeUseWorkflowGroup = new TreeUseWorkflowGroup();
      treeUseWorkflowGroup.setID(workflowGroup.getID());
      treeUseWorkflowGroup.setGroupName(workflowGroup.getGroupName());
      treeUseWorkflowGroup.setCreatorID(workflowGroup.getCreatorID());
      jCBWorkflowGroup.addItem(treeUseWorkflowGroup);
      if(groupID.intValue() ==treeUseWorkflowGroup.getID().intValue() ){
        jCBWorkflowGroup.setSelectedIndex(i);
      }

    }

    for(int i=0; i<workflowCategoryList.size(); i++) {
    //  WorkflowRecord workflowRecord = (WorkflowRecord)workflowRecordList.get(grandChildIndex);
        try{
            Object tmpObj = workflowCategoryList.get(i);
            Integer objID = null;
            String objText = null;
            SetupOptionWorkflowCategory setupOptionWorkflowCategory=(SetupOptionWorkflowCategory)tmpObj;

            //Method getIDMethod = Class.forName("SetupOptionWorkflowCategory").getMethod("getID", null);
            //Method getTextMethod = Class.forName("WorkflowCategoryRecord").getMethod("getWorkflowCategoryName", null);
            objID = setupOptionWorkflowCategory.getID();
            objText = setupOptionWorkflowCategory.getWorkflowCategoryName();
            ListObject workflowCategoryRecord = new ListObject();
            workflowCategoryRecord.setID(objID.toString());
            workflowCategoryRecord.setName(objText);
            jCBWorkflowCategory.addItem(workflowCategoryRecord);
        }catch(Exception e){

        }
    }

    for(int i=0; i<interruptList.size(); i++) {
      //  WorkflowRecord workflowRecord = (WorkflowRecord)workflowRecordList.get(grandChildIndex);
          try{
            String[] tmpObj = (String[])interruptList.get(i);
            String objID = null;
            String objText = null;
            objID = tmpObj[0];
            objText = tmpObj[1];
            ListObject interrupt = new ListObject();
            interrupt.setID(objID);
            interrupt.setName(objText);
            jCBInterruptWorkflowRecordID.addItem(interrupt);
          }catch(Exception e){

          }
      }



  }

  private void initBindList(Integer categoryID){
    ObjectInputStream inputFromServlet = null;
    List workflowbindList = new ArrayList();
    List bindWithSelectList = new ArrayList();
    String workflowID;
    if(treeUseWorkflowRecord==null){
      workflowID="";
    } else {
      workflowID = treeUseWorkflowRecord.getID().toString();
    }
    getDataURL  = "/workflow/appletMiddleware?dataType=GET_BINDWITH&workflowRecordID="+workflowID+"&categoryID="+categoryID.toString();
    try{
      inputFromServlet = httpOperation.getObjectInputStreamFromServlet(getDataURL);

      if(inputFromServlet == null){
        return;
      }

      Object obj = null;
      //obj = inputFromServlet.readObject();
    //  get bind list for select
      obj = inputFromServlet.readObject();
      if (obj instanceof List) {
      	workflowbindList = (List) obj;
      } else if (obj instanceof Exception) {
        //otherwise type cast it to Exception and throw that exception.
      throw (Exception) obj;
      }
      String methodName,className;
        if (SystemWorkflowConstant.DMS_CREATE_PUBLIC_DOCUMENT.equals(categoryID.toString()) || SystemWorkflowConstant.DMS_CREATE_SCANNED_DOCUMENT.equals(categoryID.toString())) {
            methodName = "getRootName";
            className = "com.dcivision.dms.bean.DmsRoot";
        } else if (SystemWorkflowConstant.DMS_CREATE_PUBLIC_UDF_DOCUMENT.equals(categoryID.toString()) || SystemWorkflowConstant.DMS_CREATE_SCANNED_UDF_DOCUMENT.equals(categoryID.toString())) {
            methodName = "getUserDefinedType";
            className = "com.dcivision.framework.bean.SysUserDefinedIndex";
        } else if (SystemWorkflowConstant.FMB_SUBMISSION_BY_FORM.equals(categoryID.toString())) {
            methodName = "getTitle";
            className = "com.dcivision.form.bean.FormRecord";
        } else if (SystemWorkflowConstant.FMB_SUBMISSION_BY_GROUP.equals(categoryID.toString())) {
            methodName = "getGroupName";
            className = "com.dcivision.form.bean.FormGroup";
        } else {
          methodName = "";
          className = "";
        }
      DefaultListModel listModel = new DefaultListModel();
      for(int i=0; i<workflowbindList.size() ; i++) {
        Object tmpObj = workflowbindList.get(i);
        Integer objID = null;
        String objText = null;
        Method getIDMethod = Class.forName(className).getMethod("getID", null);
        Method getTextMethod = Class.forName(className).getMethod(methodName, null);
        objID = (Integer) getIDMethod.invoke(tmpObj, null);
        objText = (String) getTextMethod.invoke(tmpObj, null);
        ListObject workflowBind = new ListObject();
        workflowBind.setID(objID.toString());
        workflowBind.setName(objText);
        listModel.addElement(workflowBind);

      }
      jList.setModel(listModel);
      //System.out.println(listModel.size());
      //    get selected  category
      obj = inputFromServlet.readObject();
      if (obj instanceof List) {
        bindWithSelectList = (List) obj;
      } else if (obj instanceof Exception) {
        //otherwise type cast it to Exception and throw that exception.
        throw (Exception) obj;
      }
      String[] bindWithIDList = new String[bindWithSelectList.size()];
      for(int i=0;i<bindWithSelectList.size();i++){
        bindWithIDList[i] = ((MtmWorkflowRecordObjectLink)bindWithSelectList.get(i)).getObjectID().toString();
      }
      WindowUtilities.setListItemByIDs(jList,bindWithIDList);

    }catch(Exception e){

    }
  }

  public void initRecordInfo(){
    ObjectInputStream inputFromServlet = null;
    List workflowbindList = new ArrayList();
    List bindWithSelectList = new ArrayList();
    getDataURL  = "/workflow/appletMiddleware?dataType=GET_WORKFLOWRECORD&workflowRecordID="+treeUseWorkflowRecord.getID().toString();

    try{
      inputFromServlet = httpOperation.getObjectInputStreamFromServlet(getDataURL);

      if(inputFromServlet == null){
        return;
      }

      Object obj = null;
      obj = inputFromServlet.readObject();
      if (obj instanceof WorkflowRecord) {
        workflowRecord = (WorkflowRecord) obj;
      } else if (obj instanceof Exception) {
        //otherwise type cast it to Exception and throw that exception.
        throw (Exception) obj;
      }
    }catch(Exception e){

    }
    if(("E".equals(this.navMode )|| "V".equals(this.navMode))&&workflowRecord!=null){

        this.ID = workflowRecord.getID().toString() ;
        this.recordStatus   = workflowRecord.getRecordStatus();
        this.updateCount    = workflowRecord.getUpdateCount().toString() ;
        this.creatorID      = workflowRecord.getCreatorID().toString() ;
        this.createDate     = workflowRecord.getCreateDate().toString() ;
        this.updaterID      = workflowRecord.getUpdaterID().toString() ;
        this.updateDate     = workflowRecord.getUpdateDate().toString() ;
        this.interruptSubmitter = workflowRecord.getInterruptSubmitter();
        jTFWorkflowCode.setText(workflowRecord.getWorkflowCode() );
        jTFWorkflowVer.setText(workflowRecord.getWorkflowVersion() );
        jTADescription.setText(workflowRecord.getDescription() );
        jTFStartDate.setText(workflowRecord.getStartDate()!=
          null?workflowRecord.getStartDate().toString().split(" ")[0]:"");
        jTFEndDate.setText(workflowRecord.getEndDate()!=
            null?workflowRecord.getEndDate().toString().split(" ")[0]:"");

        if ("R".equals(workflowRecord.getStatus())){
            jCBStatus.setSelectedIndex(1);
            jCBStatus.setEnabled(false);
        }
        if("Y".equals(workflowRecord.getAllowInterrupt())){
          jRByes.setSelected(true);
        }
        WindowUtilities.setListItemByID(jCBWorkflowCategory,workflowRecord.getWorkflowCategoryID().toString());
        jCBStatus.setVisible(true);
    } else {
      jCBStatus.setVisible(false);
    }


    if("V".equals(this.navMode)){
        jTFWorkflowCode.setEditable(false);
        jTFWorkflowVer.setEditable(false);
        jTADescription.setEditable(false);
        jTFStartDate.setEditable(false);
        jTFEndDate.setEditable(false);
        jCBStatus.setEditable( false);
        jCBWorkflowCategory.setEditable(false);
        jCBWorkflowGroup.setEnabled( false);
        jButton1.setEnabled(false);
    }



  }


  private boolean postDataToAction(){
    boolean isSuccess = false;
    try{
      if(Utility.isEmpty(jTFWorkflowCode.getText())){
        String message = WindowUtilities.getResouceByCode(httpOperation, hostURL, new int[]{0,11});
        workflowEditor.getEditor().outputMessage(message, false);
        return false;
      }

      if(Utility.isEmpty(jTFWorkflowVer.getText())){
        String message = WindowUtilities.getResouceByCode(httpOperation, hostURL, new int[]{0,12});
        workflowEditor.getEditor().outputMessage(message, false);
        return false;
      }
      httpOperation.reset() ;
      httpOperation.setSubmissionURL(maintWorkflowRecordURL);
      httpOperation.addHtmlFormText(new HtmlFormText("opMode", this.opMode ));
      httpOperation.addHtmlFormText(new HtmlFormText("navMode", this.navMode ));
      httpOperation.addHtmlFormText(new HtmlFormText("ID", this.ID ));
      httpOperation.addHtmlFormText(new HtmlFormText("recordStatus", this.recordStatus ));
      httpOperation.addHtmlFormText(new HtmlFormText("updateCount", this.updateCount ));
      httpOperation.addHtmlFormText(new HtmlFormText("creatorID", this.creatorID ));
      httpOperation.addHtmlFormText(new HtmlFormText("createDate", this.createDate ));
      httpOperation.addHtmlFormText(new HtmlFormText("updaterID", this.updaterID ));
      httpOperation.addHtmlFormText(new HtmlFormText("updateDate", this.updateDate ));

      httpOperation.addHtmlFormText(new HtmlFormText("workflowCode", jTFWorkflowCode.getText()));
      httpOperation.addHtmlFormText(new HtmlFormText("workflowVersion", jTFWorkflowVer.getText()));
      httpOperation.addHtmlFormText(new HtmlFormText("workflowCategoryID",
              ((ListObject)jCBWorkflowCategory.getItemAt(jCBWorkflowCategory.getSelectedIndex()))
                              .getID().toString() ));
      httpOperation.addHtmlFormText(new HtmlFormText("workflowGroupID",
              ((TreeUseWorkflowGroup)jCBWorkflowGroup.getItemAt(jCBWorkflowGroup.getSelectedIndex()))
                              .getID().toString()  ));
      Object[] selectObject = jList.getSelectedValues();
      for(int i=0;i<selectObject.length;i++){
          httpOperation.addHtmlFormText(new HtmlFormText("categoryObjectID", ((ListObject)selectObject[i]).getID().toString()));
      }
      httpOperation.addHtmlFormText(new HtmlFormText("startDate", jTFStartDate.getText().split(" ")[0]+" 00:00:00"));
      if(!Utility.isEmpty(jTFEndDate.getText())){
        httpOperation.addHtmlFormText(new HtmlFormText("endDate", jTFEndDate.getText().split(" ")[0]+" 00:00:00"));
      }
      httpOperation.addHtmlFormText(new HtmlFormText("description", jTADescription.getText()));
      httpOperation.addHtmlFormText(new HtmlFormText("startDate", jCBStatus.getSelectedItem().toString()));

      if(jCBStatus.getSelectedIndex()==0){
          httpOperation.addHtmlFormText(new HtmlFormText("status", "P"));
      }else{
          httpOperation.addHtmlFormText(new HtmlFormText("status", "R"));
      }
      if(!Utility.isEmpty(interruptSubmitter)){
        httpOperation.addHtmlFormText(new HtmlFormText("interruptSubmitter", interruptSubmitter));
      }
      if(jRByes.isSelected()){
        httpOperation.addHtmlFormText(new HtmlFormText("allowInterrupt", "Y"));
      } else {
        httpOperation.addHtmlFormText(new HtmlFormText("allowInterrupt", "N"));

      }
      String returnValue = httpOperation.transmit().toString();
      returnValue = returnValue.replaceAll("\n","");

      workflowEditor.getEditor().outputMessage(returnValue, false);
      isSuccess = true;
    }catch(Exception e){
        System.out.println(e);
        isSuccess = false;
    }
    return isSuccess;
  }

  void jRByes_actionPerformed(ActionEvent e) {

  }

  void jBPermission_actionPerformed(ActionEvent e) {
    InterruptOwner interruptOwner = new InterruptOwner(this, "Interrupt Owner", true);
    interruptOwner.setBounds(this.getX(),this.getY(),630,320);
    interruptOwner.setLocationRelativeTo(this);
    interruptOwner.show();
  }

}



class WorkflowRecordInfoWindow_jButton_actionAdapter implements java.awt.event.ActionListener {
  JTextField adaptee;

  WorkflowRecordInfoWindow_jButton_actionAdapter(JTextField adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    //adaptee.jButton3_actionPerformed(e);
    JDialog frm = new JDialog();
    frm.getContentPane().setLayout(new BorderLayout());
    CalendarControl calendarControl = new CalendarControl(frm);
    calendarControl.setJTFDate(adaptee);
    frm.getContentPane().add(calendarControl);
    frm.setLocationRelativeTo(adaptee);
    frm.setModal(true);
    frm.pack();
    frm.show();
  }
}

class WorkflowRecordInfoWindow_jButton1_actionAdapter implements java.awt.event.ActionListener {
  WorkflowRecordInfoWindow adaptee;

  WorkflowRecordInfoWindow_jButton1_actionAdapter(WorkflowRecordInfoWindow adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton1_actionPerformed(e);
  }
}

class WorkflowRecordInfoWindow_jButton2_actionAdapter implements java.awt.event.ActionListener {
  WorkflowRecordInfoWindow adaptee;

  WorkflowRecordInfoWindow_jButton2_actionAdapter(WorkflowRecordInfoWindow adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton2_actionPerformed(e);
  }
}
class WorkflowCategoryRecord {
    private Integer ID;
    private String  name ;

    public void setID(Integer ID){
        this.ID = ID;
    }
    public Integer getID(){
        return this.ID;
    }

    public void setName(String name){
        this.name = name;
    }

    public String getName(){
        return this.name ;
    }

    public String toString(){
        return this.name ;
    }
}

class WorkflowBind {
  private Integer ID;
  private String  name ;

  public void setID(Integer ID){
      this.ID = ID;
  }
  public Integer getID(){
      return this.ID;
  }

  public void setName(String name){
      this.name = name;
  }

  public String getName(){
      return this.name ;
  }

  public String toString(){
      return this.name ;
  }
}

